"""
# -*- coding: utf-8 -*-
# @Time    : 2023/6/14 8:05
# @Author  : 王摇摆
# @FileName: MultiOutputClassifier.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
from sklearn.ensemble import RandomForestClassifier
from sklearn.multioutput import MultiOutputClassifier

from Dataset.Data import y_train, X_train, X_test, y_test
import numpy as np

# 制作多输出分类标签并进行合并
y_train_1st = y_train.copy()
y_train_1st[y_train <= 4] = 0
y_train_1st[np.logical_and(y_train > 4, y_train < 7)] = 1
y_train_1st[y_train >= 7] = 2
y_train_multioutput = np.c_[y_train_1st, y_train]
# print(y_train_multioutput)
print('2. 标签已制作完成')

MO = MultiOutputClassifier(RandomForestClassifier(n_estimators=100))
print('3. 模型已构建成功')

MO.fit(X_train, y_train_multioutput)
print('4. 模型已学习完毕')

predictions = MO.predict(X_test[:5, :])
print('5. 模型已预测完毕')
#
# print('===============预测结果如下==================')
# category_mapping = {0: "小于等于4", 1: "4和7之间", 2: "大于等于7"}
# for i, (prediction, true_label) in enumerate(zip(predictions, y_train_multioutput[:5])):
#     predicted_category = category_mapping[prediction[0]]  # 模型的预测类别
#     predicted_number = prediction[1]  # 模型的预测数字
#     true_category = category_mapping[true_label[0]]  # 真实类别
#     true_number = true_label[1]  # 真实数字
#     is_correct = "正确" if (predicted_category == true_category and predicted_number == true_number) else "错误"  # 判断预测结果是否与真实结果一致
#     print(f"样本{i + 1:<4}的预测结果为：{predicted_number:<4}，它[{predicted_category:<6}]，"
#           f"预测结果{is_correct}")

# 还是有点问题，但是一定要知道没有改不通改不了的代码